package com.ysd.lis.util.lab;

import cn.hutool.core.bean.BeanUtil;
import com.ysd.lis.entity.lab.LabItemDict;
import com.ysd.lis.entity.lab.LabMaininfo;
import com.ysd.lis.entity.lab.LabReqdetailDel;
import com.ysd.lis.entity.lab.LabRptresult;

public class CalcItemFormulaReplcae extends LabItemDict {
    public String ReplaceCondition(String formula, LabMaininfo mainInfo, LabRptresult result) {

        formula = formula.replace("orgId", BeanUtil.isEmpty(mainInfo.getOrgId()) ? " 1=2 AND 'A' " : "'" + mainInfo.getOrgId() + "'")
                .replace("orgid", BeanUtil.isEmpty(mainInfo.getOrgId()) ? " 1=2 AND 'A' " : "'" + mainInfo.getOrgId() + "'")
                //申请科室
                .replace("reqDept", BeanUtil.isEmpty(mainInfo.getReqDept()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqDept() + "'")
                .replace("reqdept", BeanUtil.isEmpty(mainInfo.getReqDept()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqDept() + "'")
                .replace("DPTID", BeanUtil.isEmpty(mainInfo.getReqDept()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqDept() + "'")
                .replace("dptid", BeanUtil.isEmpty(mainInfo.getReqDept()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqDept() + "'")
                //申请病区
                .replace("reqWard", BeanUtil.isEmpty(mainInfo.getReqWard()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqWard() + "'")
                .replace("reqward", BeanUtil.isEmpty(mainInfo.getReqWard()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqWard() + "'")
                //病人来源
                .replace("patType", BeanUtil.isEmpty(mainInfo.getPatType()) ? " 1=2 AND 'A' " : "'" + mainInfo.getPatType() + "'")
                .replace("pattype", BeanUtil.isEmpty(mainInfo.getPatType()) ? " 1=2 AND 'A' " : "'" + mainInfo.getPatType() + "'")
                .replace("PATTYPE", BeanUtil.isEmpty(mainInfo.getPatType()) ? " 1=2 AND 'A' " : "'" + mainInfo.getPatType() + "'")
                //采样类型
                .replace("sampleType", BeanUtil.isEmpty(mainInfo.getSampleType()) ? " 1=2 AND 'A' " : "'" + mainInfo.getSampleType() + "'")
                .replace("sampletype", BeanUtil.isEmpty(mainInfo.getSampleType()) ? " 1=2 AND 'A' " : "'" + mainInfo.getSampleType() + "'")
                .replace("SAMPLETYPE", BeanUtil.isEmpty(mainInfo.getSampleType()) ? " 1=2 AND 'A' " : "'" + mainInfo.getSampleType() + "'")
                //条码号
                .replace("reqNo", BeanUtil.isEmpty(mainInfo.getReqNo()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqNo() + "'")
                .replace("reqno", BeanUtil.isEmpty(mainInfo.getReqNo()) ? " 1=2 AND 'A' " : "'" + mainInfo.getReqNo() + "'")
                //性别
                .replace("[SEX]", BeanUtil.isEmpty(mainInfo.getSex()) ? " 1=2 AND 'A' " : "'" + mainInfo.getSex() + "'")
                .replace("[sex]", BeanUtil.isEmpty(mainInfo.getSex()) ? " 1=2 AND 'A' " : "'" + mainInfo.getSex() + "'")
                .replace("sex", BeanUtil.isEmpty(mainInfo.getSex()) ? " 1=2 AND 'A' " : "'" + mainInfo.getSex() + "'")
                .replace("SEX", BeanUtil.isEmpty(mainInfo.getSex()) ? " 1=2 AND 'A' " : "'" + mainInfo.getSex() + "'")
                //年龄
                .replace("[AGE]", BeanUtil.isEmpty(mainInfo.getAge()) ? " 1=2 AND 'A' " : " " + mainInfo.getAge() + " ")
                .replace("[age]", BeanUtil.isEmpty(mainInfo.getAge()) ? " 1=2 AND 'A' " : " " + mainInfo.getAge() + " ")
                .replace("age", BeanUtil.isEmpty(mainInfo.getAge()) ? " 1=2 AND 'A' " : " " + mainInfo.getAge() + " ")
                .replace("AGE", BeanUtil.isEmpty(mainInfo.getAge()) ? " 1=2 AND 'A' " : " " + mainInfo.getAge() + " ")
                //2023-02-17添加,妊娠,采样部位体位等
                .replace("phycycle", BeanUtil.isEmpty(mainInfo.getPhyCycel()) ? " 1=2 AND 'A' " : "'" + mainInfo.getPhyCycel() + "'")
                //生理周期
                .replace("phyCycel", BeanUtil.isEmpty(mainInfo.getPhyCycel()) ? " 1=2 AND 'A' " : "'" + mainInfo.getLactation() + "'")
                .replace("MENSTRUALCYCLE", BeanUtil.isEmpty(mainInfo.getPhyCycel()) ? " 1=2 AND 'A' " : "'" + mainInfo.getLactation() + "'")
                //脯乳期
                .replace("lactation", BeanUtil.isEmpty(mainInfo.getLactation()) ? " 1=2 AND 'A' " : "'" + mainInfo.getLactation() + "'")
                .replace("ISINLACTATION", BeanUtil.isEmpty(mainInfo.getLactation()) ? " 1=2 AND 'A' " : "'" + mainInfo.getLactation() + "'")
                //妊娠期
                .replace("gestation", BeanUtil.isEmpty(mainInfo.getGestation()) ? " 1=2 AND 'A' " : "'" + mainInfo.getGestation() + "'")
                //孕周
                .replace("gestationWeek", BeanUtil.isEmpty(mainInfo.getGestationWeek()) ? " 1=2 AND 'A' " : "'" + mainInfo.getGestationWeek() + "'")
                .replace("gestationweek", BeanUtil.isEmpty(mainInfo.getGestationWeek()) ? " 1=2 AND 'A' " : "'" + mainInfo.getGestationWeek() + "'")
                //孕次
                .replace("gestationTimes", BeanUtil.isEmpty(mainInfo.getGestationTimes()) ? " 1=2 AND 'A' " : "'" + mainInfo.getGestationTimes() + "'")
                //诊断
                .replace("diagnose", BeanUtil.isEmpty(mainInfo.getDiagnose()) ? " 1=2 AND 'A' " : "'" + mainInfo.getDiagnose() + "'")
                //标本号
                .replace("sampleNo", BeanUtil.isEmpty(mainInfo.getDiagnose()) ? " 1=2 AND 'A' " : "'" + mainInfo.getDiagnose() + "'")
                .replace("sampleno", BeanUtil.isEmpty(mainInfo.getDiagnose()) ? " 1=2 AND 'A' " : "'" + mainInfo.getDiagnose() + "'")
                .replace("SAMPLENO", BeanUtil.isEmpty(mainInfo.getDiagnose()) ? " 1=2 AND 'A' " : "'" + mainInfo.getDiagnose() + "'");

        if (!BeanUtil.isEmpty(result)) {
            formula = formula.replace("feeCode", BeanUtil.isEmpty(result.getFeeCode()) ? " 1=2 AND 'A' " : "'" + result.getFeeCode() + "'")
                    .replace("feecode", BeanUtil.isEmpty(result.getFeeCode()) ? " 1=2 AND 'A' " : "'" + result.getFeeCode() + "'")
                    .replace("FEEID", BeanUtil.isEmpty(result.getFeeCode()) ? " 1=2 AND 'A' " : "'" + result.getFeeCode() + "'")
                    .replace("feeid", BeanUtil.isEmpty(result.getFeeCode()) ? " 1=2 AND 'A' " : "'" + result.getFeeCode() + "'")
                    //检验项目
                    .replace("itemNo", BeanUtil.isEmpty(result.getItemNo()) ? " 1=2 AND 'A' " : "'" + result.getItemNo() + "'")
                    .replace("itemno", BeanUtil.isEmpty(result.getItemNo()) ? " 1=2 AND 'A' " : "'" + result.getItemNo() + "'")
                    //检验结果
                    .replace("testResult", BeanUtil.isEmpty(result.getTestResult()) ? "" : result.getTestResult())
                    .replace("testresult", BeanUtil.isEmpty(result.getTestResult()) ? "" : result.getTestResult())
                    //替换回车
                    .replace("\n", " ");
        }
        return formula;
    }

    public String ReplaceConditionWhere(String formula) {
        //声明一个字符串数组
        String[] values = {"orgId", "reqDept", "reqdept", "DPTID", "dptid", "reqWard", "reqward", "reqNo", "reqno", "patType",
                "pattype", "PATTYPE", "sampleType", "sampletype", "SAMPLETYPE", "sex", "SEX", "age", "AGE", "phycycle",
                "phyCycel", "MENSTRUALCYCLE", "lactation", "ISINLACTATION", "gestation", "gestationWeek", "gestationweek",
                "gestationTimes", "diagnose", "sampleNo", "sampleno", "SAMPLENO", "feeCode", "feecode", "FEEID",
                "feeid", "ITEMNO", "itemno", "testResult", "testresult",};
        //循环values
        for (String value : values) {
            formula = formula.replace(value, "t1." + value);
        }
        return formula;
    }
}
